# coding:UTF-8
# ________________________
# Project_Name:pyzidonghua
# File_Name:Administrator
# Author:Administrator
# Date_Time:2022/4/26 14:10
# Description:
# ________________________
import unittest  # 导入测试框架

from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait  # 导入显式等待类
from selenium.webdriver.support import expected_conditions  # 导入等待条件
from selenium.webdriver.common.action_chains import ActionChains

class ZHYtest(unittest.TestCase):

    # 测试前：前置条件
    def setUp(self) -> None:

        self.driver = webdriver.Chrome()
        # 生成显式等待对象，设置最大元素等待时间
        self.wait = WebDriverWait(self.driver, 30)
        # 最大化浏览器
        self.driver.maximize_window()
        #进入浏览器URL地址
        self.driver.get('http://localhost/cloud/#/open/login')

    # 测试中：测试步骤
    def test(self) -> None:
        # 输入用户名
        self.wait.until(expected_conditions.visibility_of_element_located((By.XPATH,'//*[@id="account"]/input')))
        self.driver.find_element(By.XPATH,'//*[@id="account"]/input').send_keys('admin')
        # 输入密码
        self.wait.until(expected_conditions.visibility_of_element_located((By.XPATH,'//*[@id="password"]/input')))
        self.driver.find_element(By.XPATH,'//*[@id="password"]/input').send_keys('123456')
        # 输入验证码
        self.wait.until(expected_conditions.visibility_of_element_located((By.XPATH,'//*[@id="authCode"]/div/input')))
        self.driver.find_element(By.XPATH,'//*[@id="authCode"]/div/input').send_keys('8888')
        # 点击登录
        self.wait.until(expected_conditions.visibility_of_element_located
                        ((By.XPATH,'//*[@id="root"]/div/div[1]/form/div[5]/div/div/span/button')))
        self.driver.find_element\
            (By.XPATH,'//*[@id="root"]/div/div[1]/form/div[5]/div/div/span/button').click()




    # 测试后：清理测试环境
    def tearDown(self) -> None:
            self.driver.quit()
